﻿using Absky.Business.OrganizationManage;
using Absky.Util;
using Absky.Web.Controllers;
using Microsoft.AspNetCore.Mvc;
using System.IO;
using System.Threading.Tasks;

namespace Absky.Web.Areas.OrganizationModule.Controllers
{
    [Area("OrganizationModule")]
    public class UserController : BaseController
    {
        private readonly UserBLL userBLL = new UserBLL();
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 获取头像
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<FileStreamResult> GetImg(long userId)
        {
            var data = await userBLL.GetEntity(userId);
            string fileHeadImg = GlobalContext.Configuration.GetSection("UploadConfig:FileHeadImg").Value;
            string img = null;
            if (data.Code == Enum.ResultCodeEnum.Success)
            {
                var entity = data.Data;
                
                if (entity != null)
                {
                    if(entity.Gender == 0)
                    {
                        img = Path.Combine(fileHeadImg, "on-girl.jpg");
                    }
                    else
                    {
                        img = Path.Combine(fileHeadImg, "on-boy.jpg");
                    }
                }
                else
                {
                    img = Path.Combine(fileHeadImg, "on-boy.jpg");
                }
            }
            var stream = new FileStream(img, FileMode.Open, FileAccess.Read, FileShare.Read);
            return new FileStreamResult(stream, "image/png");
        }
    }
}
